from urllib.request import urlopen
from bs4 import BeautifulSoup
import re

pages = set()
# https://baike.baidu.com/item/%E5%91%A8%E6%9D%B0%E4%BC%A6/129156

def get_links(url):
    html = urlopen("https://baike.baidu.com" + url)
    bsObj = BeautifulSoup(html, "html.parser")
    for link in bsObj.findAll("a", href = re.compile("^(/item/)")):
        if link.attrs['href'] not in pages:
            newPage = link.attrs['href']
            print(newPage)
            pages.add(newPage)
            get_links(newPage)

get_links("")
